<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page contentType="text/html; charset=UTF-8" language="java"
	import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/page/base.jsp"%>
<%@ taglib prefix="d" uri="/doone-comm-ui-tags"%>

<html>
	<head>
		<title>企业门店信息</title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->


		<style type="text/css">
.sideDiv {
	z-index: 9999;
	margin-bottom: 3px;
	display: none;
	position: absolute;
	border: solid 1px #6e8bde;
}

.mapDiv {
	clear: both;
	margin: 4px;
	padding: 2px;
}

.filterDiv {
	color: #C7EDCC;
	background-color: inherit;
	position: absolute;
	top: 0px;
	left: 0px;
	filter: alpha(opacity =50);
}
.selectedTag{float:left;display:inline-block;margin-right:10px;margin-bottom:10px;padding:5px;border:solid 1px #339900;color:#339900}
.notSelectedTag{float:left;display:inline-block;margin-right:10px;margin-bottom:10px;padding:5px;border:solid 1px #999999;color:#999999}
ul#addedTags li a{margin-left:10px;color:#CC0000;text-decoration:none}
ul#existTags li a{margin-left:10px;color:#CC0000;text-decoration:none}
ul#addedTags li a:hover{color:#cc0000}
</style>
		<link type="text/css" href="<%=path%>/manage/css/layout.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="<%=path%>/manage/css/Tooltip.css" />
        <link type="text/css" href="<%=path%>/manage/css/new_style.css" rel="stylesheet" />
        
		<script type="text/javascript"
			src="<%=path%>/manage/js/jquery-1.4.4.min.js"></script>

		<script type="text/javascript"
			src="<%=path%>/manage/js/easyTooltip.js"></script>
		<script type="text/javascript"
			src="<%=path%>/manage/js/jquery-ui-1.8.11.custom.min.js"></script>
		<script type="text/javascript"
			src="<%=path%>/manage/js/jquery.wysiwyg.js"></script>
		<script type="text/javascript"
			src="<%=path%>/manage/js/hoverIntent.js"></script>
		<script type="text/javascript" src="<%=path%>/manage/js/superfish.js"></script>
		<script type="text/javascript" src="<%=path%>/manage/js/custom.js"></script>
		<script type="text/javascript"
			src="<%=path%>/manage/js/My97DatePicker/WdatePicker.js"></script>
		<%-- 验证js Start --%>
		<script type="text/javascript" src="<%=path%>/manage/js/Tooltip.js"></script>
		<script type="text/javascript"
			src="<%=path%>/manage/js/jquery.validate.min.js"></script>
		<script type="text/javascript"
			src="<%=path%>/manage/js/jquery.validate.methods.min.js"></script>
		<script type="text/javascript"
			src="<%=path%>/manage/js/jquery.validate.defaults.js"></script>
		<script type="text/javascript"
			src="<%=path%>/manage/js/jquery_form.js"></script>
		<!-- map
		<script
			src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true&amp;key=AIzaSyBfDKek1RkSTOCAgRJT95mu2P8jV_vj9Ts"
			type="text/javascript"></script>
		 -->
	</head>


	<script type="text/javascript">
	//用于判断还是更新 tru更新 false增加
	var falg = true;
	//企业门店编辑	
	function editEnterShop(intShopId) {
		//$("#varShopName").removeErrorMessageAndClass();	
		falg = true;
		$.ajax({
			url : root + '/enterShop/getEditEnterShop.action',
			method : 'post',
			dataType : 'json',
			data : {
				'intShopId' : intShopId
			},
			success : function(data) {
				//给form的文本赋值
				//门店名称		
				$("#varShopName").attr("value", data.varShopName);
				//国家
				$("#varShopCountry").attr("value", data.varShopCountry);
				//省份
				$("#varShopProvince").attr("value", data.varShopProvince);
				//城市
				$("#varShopCity").attr("value", data.varShopCity);
				//经度
				$("#varShopLongitude").attr("value", data.varShopLongitude);
				//纬度
				$("#varShopLatitude").attr("value", data.varShopLatitude);
				//邮编
				$("#varShopPostnum").attr("value", data.varShopPostnum);
				//电话
				$("#varShopPhonenum").attr("value", data.varShopPhonenum);
				//地址
				$("#varShopAddress").attr("value", data.varShopAddress);
				if(data.varThumbImg!=null){
					$("#varThumbImg").show();
					$("#varThumbImg").attr("src", serverUrl+data.varThumbImg);
				} else {
					$("#varThumbImg").hide();
				}
				$("#varDesc").attr("value", data.varDesc);
				$("#varOpenTime").attr("value", data.varOpenTime);
				$("#varBusinessArea").attr("value", data.varBusinessArea);
				if(data.varIconUrl!=null){
					$("#varIconUrl").show();
					$("#varIconUrl").attr("src", serverUrl+data.varIconUrl);
				} else {
					$("#varIconUrl").hide();
				}
				$("#intShopId").attr("value", data.intShopId);
				//tags
				var existTags = "";
				var style="";
				$.each(data.usedTags,function(i,val){
					if(val.status==1){
						style="selectedTag";
					} else {
						style="notSelectedTag";
					}
					existTags = existTags + "<li class=\""+style+"\" index=\""+val.id+"\"><span>"+val.title+"</span><a href='#' onclick='javascript:delExistTag(this);'>X</a></li>";
				});
				$("#existTags").html(existTags);
				$("#selectedTagsContainer").val(data.datUpdateDatetime);
				bindtagsEvent();				
				//打开dialog
				$("#openEnterShopDialog").dialog("open");
				$("#varShopName").focus();
			},
			error : function(err) {
				if (err.responseText != '')
					alert(err.responseText);
				else
					alert("请求失败！");
			}
		});
	}
	function bindtagsEvent() {
		$("#existTags .notSelectedTag").toggle(function(){
				$(this).attr("class","selectedTag");
				var indexs = "," + $(this).attr("index");
				$("#selectedTagsContainer").val($("#selectedTagsContainer").val()+indexs);
			},function(){
				$(this).attr("class","notSelectedTag");
				var indexs = "," + $(this).attr("index");
				var selectedTagsContainer = $("#selectedTagsContainer").val();
				var value = selectedTagsContainer.replace(indexs,"");
				$("#selectedTagsContainer").val(value);
			}
		);
		$("#existTags .selectedTag").toggle(function(){
				$(this).attr("class","notSelectedTag");
				var indexs = "," + $(this).attr("index");
				var selectedTagsContainer = $("#selectedTagsContainer").val();
				var value = selectedTagsContainer.replace(indexs,"");
				$("#selectedTagsContainer").val(value);
			},function(){
				$(this).attr("class","selectedTag");
				var indexs = "," + $(this).attr("index");
				$("#selectedTagsContainer").val($("#selectedTagsContainer").val()+indexs);
			}
		);
	}
	//企业门店增加
	function addEnterShop() {
		falg = false;
		//清空form的值
		//门店名称		
		$("#varShopName").attr("value", "");
		//国家
		$("#varShopCountry").attr("value", "");
		//省份
		$("#varShopProvince").attr("value", "");
		//城市
		$("#varShopCity").attr("value", "");
		//经度
		$("#varShopLongitude").attr("value", "");
		//纬度
		$("#varShopLatitude").attr("value", "");
		//邮编
		$("#varShopPostnum").attr("value", "");
		//电话
		$("#varShopPhonenum").attr("value", "");
		//地址
		$("#varShopAddress").attr("value", "");
		$("#intShopId").attr("value", "");
		$("#varThumbImg").attr("value", "");
		$("#varThumbImg").hide();
		$("#varDesc").attr("value", "");
		$("#varOpenTime").attr("value", "");
		$("#varBusinessArea").attr("value", "");
		$("#varIconUrl").attr("value", "");
		$("#varIconUrl").hide();
		$.ajax({
			url : root + '/enterShop/getEditEnterShop.action',
			method : 'post',
			dataType : 'json',
			data : {
				'intShopId' : -1
			},
			success : function(data) {
				//tags
				var existTags = "";
				$.each(data.usedTags,function(i,val){
					existTags = existTags + "<li class=\"notSelectedTag\" index=\""+val.id+"\"><span>"+val.title+"</span><a href='#' onclick='javascript:delExistTag(this);'>X</a></li>";
				});
				$("#existTags").html(existTags);
				bindtagsEvent();				
			},
			error : function(err) {
				if (err.responseText != '')
					alert(err.responseText);
				else
					alert("请求失败！");
			}
		});
		//打开dialog
		$("#openEnterShopDialog").dialog("open");
		$("#varShopName").focus();
	}
	//企业门店信息删除
	function delEnterShop(intShopId) {
		if (confirm("慎重考虑是否确定删除该记录?删除后无法查看该条记录！！！")) {
			$.ajax({
				url : root + '/enterShop/dodelEnterShop.action',
				method : 'post',
				data : {
					'intShopId' : intShopId
				},
				success : function(data) {
					window.location.href = root
							+ '/enterShop/getEnterShopinfo.action';
				},
				error : function(err) {
					if (err.responseText != '')
						alert(err.responseText);
					else
						alert("请求失败！");
				}
			});
		}
	}
	$(document)
			.ready(
					function() {
						//验证						
						var editEnterShopForm = $("#editEnterShopForm")
								.validate({
									rules : {
										"enterpShopTab.varShopName" : {
											required : true
										},
										"enterpShopTab.varShopCountry" : {
											required : true
										},
										"enterpShopTab.varShopProvince" : {
											required : true
										},
										"enterpShopTab.varShopCity" : {
											required : true
										},
										"enterpShopTab.varShopLongitude" : {
											required : true
										},
										"enterpShopTab.varShopLatitude" : {
											required : true
										},
										"enterpShopTab.varShopPostnum" : {
											maxlength : 6
										}
									},
									messages : {
										"enterpShopTab.varShopName" : {
											required : "门店名称必填"
										},
										"enterpShopTab.varShopCountry" : {
											required : "国家必填"
										},
										"enterpShopTab.varShopProvince" : {
											required : "省份必填"
										},
										"enterpShopTab.varShopCity" : {
											required : "城市必填"
										},
										"enterpShopTab.varShopLongitude" : {
											required : "经度必填"
										},
										"enterpShopTab.varShopLatitude" : {
											required : "纬度必填"
										},
										"enterpShopTab.varShopPostnum" : {
											maxlength : "邮编最长6位"
										}
									}
								});

						//加载dialog
						$("#openEnterShopDialog")
								.dialog(
										{
											autoOpen : false,
											width : 900,
											height : 470,
											modal : true,
											title : '企业门店信息编辑',
											buttons : {
												"保存" : function() {

													//判断验证
													if (!editEnterShopForm.valid()) {
														alert("验证没通过，数据无法保存");
													} else {
														//获取选择的tags
														var indexs = "";
														$("#existTags .selectedTag").each(function(){
															indexs = indexs + "," + $(this).attr("index");
														});
														$("#selectedTagsContainer").val(indexs);
														//判断更新还是增加 默认
														if (!falg) {
															$("#editEnterShopForm").attr("action",root+ '/enterShop/doaddEnterShop.action');
														}
														var options = {success:function(responseText, statusText){
															if(responseText.indexOf("成功")>=0) {
																destroyForm();
																$("#processStatus").hide();
																$("#openEnterShopDialog").dialog("close");
																window.location.href = root + '/enterShop/getEnterShopinfo.action';
															} else {
																alert(responseText);
															}
														}};
														$("#editEnterShopForm").ajaxSubmit(options);
														$("#processStatus").show();
													}
												},
												"取消" : function() {
													$(this).dialog("close");
													destroyForm();
												}
											},
											close : function() {
												destroyForm();
											}
										});

					});

	function destroyForm() {
		$("#editEnterShopForm")[0].reset();
		$("#newTagsContainer").val("");
		$("#selectedTagsContainer").val("");
		$("#delTagsContainer").val("");
	}

	function getEnterShop(intEnterpId) {
		window.location.href = root + '/enterShop/getEnterShopinfo.action';
	}
	//获取地图经纬度
	function showDiv(id) {
		var bgdiv = $("#" + id);

		$("<div id='filterDiv'></div>").addClass("filterDiv").width("100%")
				.height("100%").click(function() {
					hideDiv(id);
				}).appendTo("body").fadeIn(200);
		bgdiv.css({
			"position" : "absolute"
		}).animate({
			left : "20px",
			top : "20px",
			opacity : "show"
		}, "slow");

	}
	//点击确定时删除层叠，隐藏地图，并为文本框赋值，达到预期效果
	function hideDiv(id) {
		$("#filterDiv").remove();
		$("#" + id).animate({
			left : 10,
			top : 10,
			opacity : "hide"
		}, "slow");
	}
	
	//检测文件格式
	function validateFile(obj) {       
	    var filepath = obj.value;
		var fileArr = filepath.split("\\");
		var fileTArr = fileArr[fileArr.length - 1].toLowerCase().split(".");
		var filetype = fileTArr[fileTArr.length - 1];
		if (filetype != "jpg" && filetype != "png") {
			alert("必须上传jpg、png格式的文件");
			$(obj).parent().html('<input type="file" name="'+$(obj).attr("name")+'" style="width:180px" onchange="validateFile(this)">');
		}
	}
</script>
	<body>
		<div>
			<p class="sitemap">
				<s:if test="#session.enterpShopContentId>0">
					当前位置：内容管理> 地理位置列表
				</s:if>
				<s:else>
					当前位置：企业信息管理> 企业门店息管理
				</s:else>
			</p>
			<h1>
				<s:if test="#session.enterpShopContentId>0">
					地理位置列表
				</s:if>
				<s:else>
					企业门店管理
				</s:else>
			</h1>
			<div>
				<!-- Tabs -->
				<div id="tabs">
					<ul>
						<li>
							<a href="#tabs-1">门店列表</a>
						</li>

					</ul>
					<div style="margin:10px">
						<%-- 
						<a class="btn_addnew" href="javascript:addEnterShop();">增加门店</a>
						--%>
						<span style="color:red;">门店添加请到[应用内容管理]-[门店]</span>
					</div>
					<table class="fullwidth" cellpadding="0" cellspacing="0" border="0"
						id="enterInfoTab">
						<thead>

							<tr>
								<td>
									门店名称
								</td>
								<td>
									国家
								</td>
								<td>
									省份
								</td>
								<td>
									城市
								</td>
								<%-- 
								<td>
									经度
								</td>
								<td>
									纬度
								</td>
								--%>
								<td>
									邮编
								</td>
								<td>
									电话
								</td> 
								<td>
									地址
								</td>
								<td>
									操作
								</td>
							</tr>
						</thead>
						<tbody>
							<s:iterator value="shopList">
								<tr class="odd">
									<td>
										<s:property value="varShopName" />
									</td>
									<td>
										<s:property value="varShopCountry" />
									</td>
									<td>
										<s:property value="varShopProvince" />
									</td>
									<td>
										<s:property value="varShopCity" />
									</td>
									<%-- 
									<td>
										<s:property value="varShopLongitude" />
									</td>
									<td>
										<s:property value="varShopLatitude" />
									</td>
									--%>
									<td>
										<s:property value="varShopPostnum" />
									</td>
									<td>
										<s:property value="varShopPhonenum" />
									</td>

									<td>
										<s:property value="varShopAddress" />
									</td>
									<td>
										<a  class="icon icon_edit" title="编辑 " href="javascript:editEnterShop('<s:property value="intShopId" />')"></a>
										<a class="icon icon_delete" title="删除 " href="javascript:delEnterShop('<s:property value="intShopId" />')"></a>
									</td>

								</tr>
							</s:iterator>
						</tbody>
					</table>

				</div>
				<!-- 分页标签开始 -->
				<div align="right" style="float: right;">
					<d:page id="pageContent" template="details" skin="gray" >
					</d:page>
				</div>
				<!-- 分页标签结束 -->
			</div>
		</div>

		<!-- 编辑页使用的弹出层 -->
		<div id="openEnterShopDialog" style="display:none;">
			<%@ include file="shopEdit.jspf" %>
		</div>
	</body>
</html>
